#ifndef QOPENHARMONYCAPTURESESSION_H
#define QOPENHARMONYCAPTURESESSION_H

#include <qurl.h>
#include <qtimer.h>
#include <qobject.h>
#include <qelapsedtimer.h>
#include <qmediarecorder.h>
#include <private/qmediastoragelocation_p.h>

QT_BEGIN_NAMESPACE

class QOPenHarmonyCameraSession;

class QOPenHarmonyCaptureSession : public QObject
{
    Q_OBJECT

public:
    QOPenHarmonyCaptureSession(QOPenHarmonyCameraSession *cameraSession = Q_NULLPTR);
    ~QOPenHarmonyCaptureSession();

    qint64 duration() const;
    QMediaRecorder::State state() const;
    QMediaRecorder::Status status() const;
    void setState(QMediaRecorder::State state);

    QString containerFormat() const { return m_containerFormat; }
    void setContainerFormat(const QString &format);

Q_SIGNALS:
    void durationChanged(qint64 position);
    void audioInputChanged(const QString& name);
    void stateChanged(QMediaRecorder::State state);
    void actualLocationChanged(const QUrl &location);
    void statusChanged(QMediaRecorder::Status status);
    void error(int error, const QString &errorString);

private Q_SLOTS:
    void updateDuration();
    void onCameraOpened();

    void onError(int what, int extra);
    void onInfo(int what, int extra);

private:
    void start();
    void stop(bool error = false);

    void setStatus(QMediaRecorder::Status status);

    void updateViewfinder();
    void restartViewfinder();

    QOPenHarmonyCameraSession *m_cameraSession;

    QElapsedTimer m_elapsedTime;
    QTimer m_notifyTimer;
    qint64 m_duration;

    QMediaRecorder::State m_state;
    QMediaRecorder::Status m_status;

    QString m_containerFormat;
    bool m_containerFormatDirty;
};


QT_END_NAMESPACE
#endif // QOPENHARMONYCAPTURESESSION_H
